<script setup lang='ts'>
interface Props {
  modelValue: string
  loading?: boolean
  placeHolder?: string
}
defineOptions({ name: 'AppSportsSearchInput' })
defineProps<Props>()
const emit = defineEmits(['update:modelValue',])

function onInput(event: any) {
  const v = event.target.value
  emit('update:modelValue', v)
}
function onClear() {
  emit('update:modelValue', '')
}
</script>

<template>
  <div class="search-input">
    <div class="wrap">
      <input :value="modelValue" type="text" @input="onInput" :placeHolder="placeHolder">
      <div class="clear" @click="onClear">
        <BaseIcon name="uni-close2" />
      </div>
      <div v-if="loading" class="absolute left-0 right-0 bottom-0">
        <div class="h-[2px] overflow-hidden relative">
          <div class="line first"></div>
          <div class="line second"></div>
        </div>
      </div>
    </div>
  </div>
</template>

<style lang='scss' scoped>
.search-input {
  width: 100%;
  height: 40px;
  border-radius: 4px;
  border: 1px solid var(--color-bg-black-5);
  background: var(--color-bg-black-3);

  .wrap {
    width: 100%;
    height: 100%;
    position: relative;
    padding: 0 8px;
    display: flex;
    align-items: center;

    input {
      flex: 1;
      margin-right: 10px;
      color: var(--color-text-white-0);
      font-size: 14px;
      font-style: normal;
      font-weight: 590;
      line-height: 16px;
    }

    .clear {
      width: 24px;
      height: 24px;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 9px;
      border-radius: 6px;
      background: rgba(255, 255, 255, 0.05);
      cursor: pointer;
    }
  }
}

.line {
  top: 0;
  left: 0;
  width: auto;
  bottom: 0;
  position: absolute;
  background: #24ee89;
  transition: transform 0.2s linear;
  transform-origin: left;

  &.first {
    animation: bt29269 2.1s cubic-bezier(0.65, 0.815, 0.735, 0.395) infinite;
  }

  &.second {
    animation: bt29269 2.1s cubic-bezier(0.165, 0.84, 0.44, 1) infinite;
    animation-delay: 1.15s;
  }
}

@keyframes bt29269 {
  0% {
    left: -35%;
    right: 100%;
  }

  60% {
    left: 100%;
    right: -90%;
  }

  100% {
    left: 100%;
    right: 90%;
  }
}
</style>
